﻿@using Kugar.Core.ExtMethod
@using Kugar.UI.Web.AdminLTE.Enums
@using Kugar.UI.Web.AdminLTE.Helpers
@using Kugar.UI.Web.AdminLTE.Helpers.FormExtMethod
@using Kugar.UI.Web.AdminLTE.PageControls.Helpers.ButtonExtMethod
@using Newtonsoft.Json.Linq

@{
    WebUI.Title = "Index";
    WebUI.CurrentMenuKey = "Index";
}

@section scripts{
    <script>
        function addRow() {
            var tr = $('<tr class="odd" role="row">' +
                '<input type="hidden" name="hide" value="">' +
                '<td class="" style="width:20px;" "="">' +
                '<div class="webui_data_cell"><input type="checkbox" value="0" name="cc" title="" lay-skin="primary" checked=""><div class="layui-unselect layui-form-checkbox layui-form-checked" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div><div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '<td class="" style="" "="">' +
                '<div class="webui_data_cell"><input type="radio" value="0" name="rr" title="" lay-skin="primary" checked=""><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div></div></div><div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '<td class="" style="" "="">' +
                '<div class="webui_data_cell"><input type="text" lay-ignore="" class="form-control textbox cell-textbox" name="tt" value="" placeholder=""> <div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '<td class="" style="" "="">' +
                '<div class="webui_data_cell"><select class="form-control cell-select" lay-ignore="" onchanged="" name="ss">' +
                '<option value="-1">select</option>' +
                '<option value="0">s0</option>' +
                '<option value="1">s1</option>' +
                '</select>' +
                '<div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '<td class="" style="" "="">' +
                '<div class="webui_data_cell"><input type="hidden" name="101" value="tbID"><div class="input-group cell-textboxwithbutton">' +
                '<input lay-ignore="" class="form-control textbox" name="tb" value="" placeholder="">' +
                '<span class="input-group-btn"><button type="button" class="btn btn-info">...</button></span>' +
                '</div>' +
                '<div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '<td class="" style="" "="">' +
                '<div class="webui_data_cell"><input type="hidden" name="http://pic.58pic.com/58pic/17/19/64/18Q58PICmXU_1024.jpg" value="ii"><div class="cell-image" style="width:100px;height:100px;">' +
                '<img src="http://pic.58pic.com/58pic/17/19/64/18Q58PICmXU_1024.jpg" onerror="this.src=\'/adminltebase/Content/images/picerror_80_80.jpg\';"><span class="vertical-middle"></span>' +
                '</div>' +
                '<div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '<td class="" style="" "="">' +
                '<div class="webui_data_cell"><div class="datetimepicker cell-datetimepicker" data-format="yyyy-MM-dd" data-pickertype="Date" data-maxdt="" data-mindt="" data-disabled="False">' +
                '<div class="input-group">' +
                '<input type="text" placeholder="" value="" name="dd" class="form-control">' +
                '<span class="input-group-btn"><button type="button" class="btn btn-info datetimepickershow"><i class="fa fa-calendar"></i></button></span>' +
                '</div>' +
                '</div>' +
                '<div class="clearfix"></div>' +
                '</div>' +
                '</td>' +
                '</tr>');

            $("#table").DataTable().row.add(tr).draw();

            WebUIJS.RefreshEvent(tr);
        }
    </script>
}

@using (var frm = WebUI.Control.Form().WithBox().DefaultLabelWidth(2).Enctype(FormEnctype.multipart).ID("form").Post().Render())
{
    @frm.AddTextBox().Label("Text").Name("Text").Value("-1").Required().Tips("aaa").Render()
    @*
        @frm.AddDatetime().Label("Datetime").Name("Date").Value(null).Type(DatetimePickerType.Datetime).Format("yyyy-MM-dd HH:mm:ss").Required().Tips("aaa").Render()

        @frm.AddDatetimeRange().Label("DatetimeRange").Name("StartDt", "EndDt").Value(null, null).Type(DatetimePickerType.Datetime).Format("yyyy-MM-dd HH:mm:ss").Required().Tips("aaa").Render()

        @frm.AddValueRange().Label("ValueRange").Name("StartVal", "EndVal").Value("", "").Type(InputElementType.number).Required().Tips("aaa").Render()

        @frm.AddTextBoxWithButton().Label("Text&Button").Name("TextButton").Value("").WithHiddenValue("100", "TextButtonID").Required().Tips("aaa").Render()

        @frm.AddSelector().Label("Select").Name("Select").CurrentValue(1).FirstItem(new SelectorItem("select", "-1")).Options(new[]
                                                    {
                                                        new SelectorItem("s0", "0"),
                                                        new SelectorItem("s1", "1"),
                                                        new SelectorItem("s2", "2"),
                                                    }).Required().Tips("aaa").Render()

        @frm.AddCheckBoxList().Label("CheckBox").Name("CheckBox").Checked(new[] { "0", "1" }).Options(new[]
                                                        {
                                                            new SelectorItem("c0", "0"),
                                                            new SelectorItem("c1", "1"),
                                                            new SelectorItem("c2", "2"),
                                                        }).Required().Tips("aaa").Render()

        @frm.AddRadioList().Label("Radio").Name("Radio").Checked("-1").Options(new[]
                                                    {
                                                        new SelectorItem("r0", "0"),
                                                        new SelectorItem("r1", "1"),
                                                        new SelectorItem("r2", "2"),
                                                    }).Required().Tips("aaa").Render()

        @frm.AddCityPicker().Label("CityPicker").Name("pcd").ValueByName("").WithAddressBox("addr", "").Required().Tips("aaa").Render()*@

    @*@frm.AddFileUpload().Label("File").Name("File").Src("").UploadUrl("/Home/Upload").Required().Tips("aaa").Render()

        @frm.AddImageUpload().Label("Image").Name("Image").Src("").UploadUrl("/Home/Upload").Required().Tips("aaa").Render()

        @frm.AddMultiFileUpload().Label("MultiFile").Name("MultiFile").FileUrls(new[] { new SelectorItem("文件1", "http://pic.58pic.com/58pic/17/19/64/18Q58PICmXU_1024.jpg") }).UploadUrl("/Home/Upload").Required().Tips("aaa").Render()

        @frm.AddMultiImageUpload().Label("MultiImage").Name("MultiImage").Images(new[] { "http://pic.58pic.com/58pic/17/19/64/18Q58PICmXU_1024.jpg" }).UploadUrl("/Home/Upload").Required().Tips("aaa").Render()*@

    @*@frm.AddTextarea().Label("Textarea").Name("Textarea").Value("").Rows(3).Required().Tips("aaa").Render()

        @frm.AddSummerNote().Label("SummerNote").Name("SummerNote").Value("").Height("100px").Required().Tips("aaa").Render()*@

    using (frm.AddCustomContainer().Required().Label("Container").WithNameError("Container").Render())
    {
        @frm.AddCustomContent().Content(WebUI.Control.Button().Text("addRow").OnClick("addRow();").Type(ButtonTypeEnum.button).Color(ColorPaletteEnum.success)).Render()

        using (var tb = WebUI.Control.Table<object>().ID("table").Data(new object[0]).FillRowCount(3).AddRowHiddenValue(x => ("hide", $"{x}")).NoWrap().Render())
        {
            @tb.Columns.AddCustomContent().Content(@<div>
                <p>@Html.ValidationMessage($"cc_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"rr_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"tt_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"ss_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"tb_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"tbID_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"ii_{tb.CurrentRowIndex}")</p>
                <p>@Html.ValidationMessage($"dd_{tb.CurrentRowIndex}")</p>
            </div>)

            @tb.Columns.AddCheckbox().ColumnTitle("").Checked(x => false).Name(x => $"cc_{tb.CurrentRowIndex}").Value(x => tb.CurrentRowIndex.ToString())

            @tb.Columns.AddRadio().ColumnTitle("Radio").Checked(x => false).Name(x => $"rr_{tb.CurrentRowIndex}").Value(x => tb.CurrentRowIndex.ToString())

            @tb.Columns.AddTextbox().ColumnTitle("Textbox").Name(x => $"tt_{tb.CurrentRowIndex}").Value(x => "")

            @tb.Columns.AddSelector().ColumnTitle("Selector").Name(x => $"ss_{tb.CurrentRowIndex}").FirstItem(new SelectorItem("select", "-1")).Options(new[] { new SelectorItem("s0", "0"), new SelectorItem("s1", "1"), })

            @tb.Columns.AddTextboxWithButton().ColumnTitle("TextboxWithButton").Name(x => $"tb_{tb.CurrentRowIndex}").Value(x => "").WithHiddenValue(x => ($"tbID_{tb.CurrentRowIndex}", "101"))

            @tb.Columns.AddImage().ColumnTitle("Image").Src(x => "http://pic.58pic.com/58pic/17/19/64/18Q58PICmXU_1024.jpg").WithHiddenValue(x => ($"ii_{tb.CurrentRowIndex}", "http://pic.58pic.com/58pic/17/19/64/18Q58PICmXU_1024.jpg"))

            @tb.Columns.AddDatetime().ColumnTitle("Datetime").Name(x => $"dd_{tb.CurrentRowIndex}").Value(x => null)
        }
    }

    //WebUI.Control.Tree<JObject>().Source(new[]
    //{
    //    new JObject {["Title"] = "111", ["Children"] = new JArray() {new JObject {["Title"] = "1_aaa"}, new JObject {["Title"] = "1_bbb", ["Children"] = new JArray() {new JObject {["Title"] = "1_b_##"}, new JObject {["Title"] = "1_b_&&"}}}}},
    //    new JObject {["Title"] = "222", ["Children"] = new JArray() {new JObject {["Title"] = "2_aaa"}, new JObject {["Title"] = "2_bbb"}}},
    //    new JObject {["Title"] = "333", ["Children"] = new JArray() {new JObject {["Title"] = "3_aaa"}, new JObject {["Title"] = "3_bbb"}}},
    //})
    //    .Checked(x => new[] {"1_aaa", "1_b_##", "3_bbb"}.Contains(x.GetString("Title")))
    //    .Children(x => x.GetJObjectArray("Children"))
    //    .Value(x => x.GetString("Title"))
    //    .Title(x => x.GetString("Title"))
    //    .ToggleNodeOnClick(false)
    //    .Render();

    frm.AddButtonList()
        .AddButton(x => x.Text("save").DisabledAfterClick().Type(ButtonTypeEnum.submit).Color(ColorPaletteEnum.success))
        .Render();
}

